// ******************************************************************
// * Copyright(c)  Steven Lu
// * Description   : Entity_FIN_SUPPLIER_ACCOUNT
// * CreateDate    : 2012/2/2 10:17:12
// * Creater       : CodeSmith
// * LastChangeDate: 2012/2/2 10:17:12
// * LastChanger   : 2012/2/2 10:17:12
// * Version Info  : 1.0 For ESOL
// ******************************************************************

using System;
using System.Data;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Suzsoft.Smart.Data;
using ESOL.Common.Entity;
using ESOL.Common;

namespace ESOL.Business.Fin
{
/// <summary>
    /// FinSupplierAccount
    /// </summary>
    public partial class FinSupplierAccountBs
    {
        #region GetByID
        /// <summary>
        /// Get Entity
        /// </summary>
        /// <param name="objFinSupplierAccountEntity">Entity</param>
        /// <returns>Entity</returns>
        public static FinSupplierAccountEntity GetFinSupplierAccount(FinSupplierAccountEntity objFinSupplierAccountEntity)
        {
            return DataAccess.SelectSingle<FinSupplierAccountEntity>(objFinSupplierAccountEntity);
        }
        public static FinSupplierAccountEntity GetById(string accountId)
        {
            if (string.IsNullOrEmpty(accountId))
            {
                return null;
            }
            FinSupplierAccountEntity entity = new FinSupplierAccountEntity();
            entity.SupplierAccountId = accountId;
            return DataAccess.SelectSingle<FinSupplierAccountEntity>(entity);
        }
        public static FinSupplierAccountEntity GetBySupplierId(string supplierId)
        {
            if (string.IsNullOrEmpty(supplierId))
            {
                return null;
            }
            FinSupplierAccountEntity entity = new FinSupplierAccountEntity();
            entity.SupplierId = supplierId;
            FinSupplierAccountEntity account = DataAccess.SelectSingle<FinSupplierAccountEntity>(entity);
            if (account == null)
            {
                account = new FinSupplierAccountEntity();
                account.SupplierAccountId = Guid.NewGuid().ToString();
                account.SupplierId = supplierId;
                account.PurchaseOrderAmount = 0;
                account.BillingAmount = 0;
                account.PaidAmount = 0;
                account.PayableAmount = 0;
                account.ArrivedAmountNoBilling = 0;
                account.ArrivedAmountBilled = 0;
                DataAccess.Insert(account);
            }
            return account;
        }
        public static DataTable GetByCondition(string condition, string orderBy, string rowCount)
        {
            string sql = CommonFunctions.GetSelect(rowCount) + @"SA.*, SA.ARRIVED_AMOUNT_NO_BILLING - SA.BILLING_AMOUNT AS ARRIVED_AMOUNT_NON_BILLED, S.SUPPLIER_NAME
                                FROM FIN_SUPPLIER_ACCOUNT SA
                                LEFT JOIN MST_SUPPLIER S ON S.SUPPLIER_ID = SA.SUPPLIER_ID
                                WHERE 1=1 ";
            if (string.IsNullOrEmpty(condition) == false)
            {
                sql += condition;
            }
            if (string.IsNullOrEmpty(orderBy) == false)
            {
                sql += " ORDER BY " + orderBy;
            }
            DataSet ds = DataAccess.SelectDataSet(sql);
            if (ds != null && ds.Tables.Count > 0)
            {
                return ds.Tables[0];
            }
            return null;
        }
        #endregion

        #region Insert
        /// <summary>
        /// Insert Data
        /// </summary>
        /// <param name="objFinSupplierAccountEntity">Entity</param>
        /// <returns>true Insert Succeed; false Insert Fail</returns>
        public static bool InsertFinSupplierAccount(FinSupplierAccountEntity objFinSupplierAccountEntity)
        {
            return DataAccess.Insert(objFinSupplierAccountEntity);
        }

        public static bool InsertFinSupplierAccount(List<FinSupplierAccountEntity> objFinSupplierAccountEntityList)
        {
            return DataAccess.Insert(objFinSupplierAccountEntityList);
        }
        #endregion

        #region Update
        /// <summary>
        /// Update Data
        /// </summary>
        /// <param name="objFinSupplierAccountEntity">Entity</param>
        /// <returns>true Update Succeed; false Update Fail</returns>
        public static bool UpdateFinSupplierAccount(FinSupplierAccountEntity objFinSupplierAccountEntity)
        {
            return DataAccess.Update(objFinSupplierAccountEntity);
        }

        public static bool UpdateFinSupplierAccount(List<FinSupplierAccountEntity> objFinSupplierAccountEntityList)
        {
            return DataAccess.Update<FinSupplierAccountEntity>(objFinSupplierAccountEntityList);
        }
        #endregion

        #region Delete
        /// <summary>
        /// Delete Data
        /// </summary>
        /// <param name="objFinSupplierAccountEntity">Entity</param>
        /// <returns>true Delete Succeed; false Delete Fail</returns>
        public static bool DeleteFinSupplierAccount(FinSupplierAccountEntity objFinSupplierAccountEntity)
        {
            return DataAccess.Delete(objFinSupplierAccountEntity);
        }

        public static bool DeleteFinSupplierAccount(List<FinSupplierAccountEntity> objFinSupplierAccountEntityList)
        {
            return DataAccess.Delete<FinSupplierAccountEntity>(objFinSupplierAccountEntityList);
        }
        #endregion

        #region GetAll
        /// <summary>
        /// Get All Data
        /// </summary>
        /// <returns>Back All Data<returns>
        public static DataSet GetFinSupplierAccountAll()
        {
            return DataAccess.SelectAllDataSet<FinSupplierAccountEntity>();
        }
        /// <summary>
        /// Get All Data List
        /// </summary>
        /// <returns>Back All Data List<returns>
        public static List<FinSupplierAccountEntity> GetFinSupplierAccountAllList()
        {
            return DataAccess.SelectAll<FinSupplierAccountEntity>();
        }
        #endregion
	}
	
	
}	

